<?
/**
 * UserInfo.php
 *
 * This page is for users to view their account information
 * with a link added for them to edit the information.
 *
 */
include_once("include/session.php");
// Make sure user is logged in. No need to be here if not!
if(!$session->logged_in) { ?> <meta HTTP-EQUIV="REFRESH" content="0; url=main.php"> <? } 

/* Requested Username error checking */
if (isset ($_GET['id'])) {
	$usId = $_GET['id'];
	$req_user = $database->id2username($usId);
} elseif (isset ($_GET['user']))  {
	$req_user = trim($_GET['user']);
} else {die("Username not registered");}

if(!$req_user || strlen($req_user) == 0 ||
   !eregi("^([0-9a-z])+$", $req_user) ||
   !$database->usernameTaken($req_user)){
   die("Username $req_user not registered");
}
$req_user_info = $database->getUserInfo($req_user);

// Check for prior interaction
if($database->userHasScanedUser($session->username, $req_user) && strcmp($session->username,$req_user) != 0){
	$hasScaned=True;
} else { // Mark the interaction
	$hasScaned=False;
	if($session->userlevel != SMALLGAME_LEVEL){ // The race game does not track interactios
		$database->userScanUser($session->username, $req_user);
	}
	// deal with adding / subtracting points
	if($session->userlevel == USER_LEVEL ) { // Visitor scans someone
		$database->addUserPoints($session->username,VISITOR_SCAN_CREDIT);
		
	} elseif($session->userlevel == MERCHANT_LEVEL ) { // A vendor scan's someone
		$database->addUserPoints($req_user,MERCHANT_SCAN_CREDIT); // Give the cust pts
		$database->addUserPoints($session->username,VISITOR_SCAN_CREDIT);
		
	} elseif($session->userlevel == SMALLGAME_LEVEL ) { // The game guy scanned
		if($database->getUserPoints($req_user) >= SMALL_GAME_ENTER_CREDIT){
			$inGame=True;
			$database->removeUserPoints($req_user, SMALL_GAME_ENTER_CREDIT);
			$database->add2Queue($usId);
		} else { $inGame=False; }
	} elseif($session->userlevel == ADMIN_LEVEL ) { // one of the admins scaned 
		
	} else { // humm... shouldnt be here
		die("Got to location should have been");
	}
}

$userPoints = $database->getUserPoints($session->username);

?>


<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="Description" content="Information about the Symposium on Racing & Gaming, presented by the University of Arizona Race Track Industry Program. Includes sponsors, exhibitors, panel sessions, award winners, photos, transcripts and presentations" />
    <meta name="Keywords" content="horseracing, horse racing, race track education, race horse, racehorse, greyhound tracks, horsetrack, thoroughbred racing, quarterhorse racing, horse breeding, pari-mutuel, parimutuel, equine education, greyhound racing, dog racing, harness racing, horse training, symposium on racing, multi-breed, racetrack industry, turf racing, rtip, gaming, betting, racetrack betting, University of Louisville, racetrack education, racetrack school, race track school, horseracing school, horseracing college, horse racing college, racetrack college, race track college, equine school, equine college, equine program, symposium on gaming" />
 
   <title>Symposium Login</title>
    <link href="css/rtip.css" rel="stylesheet" type="text/css" media="screen" />
</head>

<body>

<div id="wrap">
    <div id="topbar">
	<a href="http://www.arizona.edu/" target="_blank"></a>
    </div>
    <div id="top">
        <div id="head_image"> </div>
    </div>

    <div id="page_head">
        <h2 id="left_head"> </h2>
        <h2 id="right_head"> </h2>

    </div>


<?
if ($session->userlevel == SMALLGAME_LEVEL) { // horse
	if($inGame){echo "<h2 align=\"center\" >".$req_user_info['fname']." ".$req_user_info['lname']." is in the game</h2>";}
	else {echo "<h2 align=\"center\" >".$req_user_info['fname']." ".$req_user_info['lname']." Needs more QRedits</h2>";}
} elseif(strcmp($session->username,$req_user) == 0){
	// Do not a thing!
} elseif($hasScaned){
	echo "<h4 align=\"center\" >".$req_user_info['fname']." ".$req_user_info['lname']."is already in your contacts</h4>";
} else {
	echo "<h4 align=\"center\" >You met ".$req_user_info['fname']." ".$req_user_info['lname'].", they have been added to your contacts</h4>";
	echo "<h4 align=\"center\" >You now have $userPoints QRedits!!</h4>"; 
}



if(strcmp($session->username,$req_user) == 0){ /* Logged in user viewing own account */
   echo "<h1 align=\"center\" >My Information</h1>";
} else{ /* Visitor not viewing own account */
   echo "<h1 align=\"center\" >User Info</h1>";
}

/* Display requested user information */
$req_user_info = $database->getUserInfo($req_user);

echo "<table align=\"left\" border=\"0\" cellspacing=\"2\" >";

	/* Username */
echo "<tr><td>Username</td><td>".$req_user_info['username']."</td></tr>";

	/* Name*/ 
echo "<tr><td>Name</td><td>".$req_user_info['fname']." ".$req_user_info['lname']."</td></tr>";

	/* Organization*/
echo "<tr><td>Organization</td><td>".$req_user_info['organization']."</td></tr>";

	/* Website*/
echo "<b><td>Website</td><td>".$req_user_info['website']."</td></tr>";

	/* Phone */
echo "<tr><td>Phone Number</td><td>".$req_user_info['phone']."</td></tr>";

	/* Email */
echo "<tr><td>Address</td><td>".$req_user_info['address']."</td></tr>";

	/* Email */
echo "<tr><td>Email</td><td>".$req_user_info['email']."</td></tr>";
	
	/* End of table */
echo "</table>";

/* If logged in user viewing own account, give link to edit */
if(strcmp($session->username,$req_user) == 0){
?>
<div align="center">
<FORM METHOD="LINK" ACTION="useredit.php">
<INPUT TYPE="submit" VALUE="Edit Account Information">
</FORM>
</div>
<?} else {?>
<div align="center">
<br /> Download Contact Information<br />
<a href="vcard_example.php?user=<?echo $req_user_info['username'];?>">
<img border="0" src="images/vcard.gif" /></a>
<br /><br />
</div>
<?}?>

<div align="center">
<FORM METHOD="LINK" ACTION="main.php">
<INPUT TYPE="submit" VALUE="Back to Home">
</FORM>
</div>

</div>
</body>
</html>
